#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>



size_t my_strlen(const char* string) {
	char* start = string;
	while (*string++)
		;
	return string - start - 1;

}
char* my_strcpy(char* Destination, const char* source) {
	char* des = Destination;
	while (*Destination++ = *source++)
		;
	return des;
}
int my_strcmp(const char* str1, const char* str2) {
	while (*str1++ == *str2++)
		;
	return *--str1 - *--str2;

}
char* my_strcat(char* Destination, const char* Source) {
	//assert(Destination&&Source);
	char* ret = Destination;
	while (*Destination++)
		;
	--Destination;
	while (*Destination++ = *Source++)
		;
	return ret;
}
char* my_strstr(const char* string, const char* strset) {
	char* str = string; 
	while(*str) {
		string = str++;
		char* strs = strset;
		while (*string++ == *strs++) {
			if (*strs == '\0')return --str;
		}
	}
	return NULL;
}


void test() {

	char P[10] = {
		'i','m','s','b','\0'
	};
	char PP[10] = { 0 };
	char* cmp = "imsrr";
	printf("str P=%s\n", P);
	printf("strlen=%d\n", my_strlen(P));
	printf("PP=%s \n", my_strcpy(PP, P));
	printf("str cmp=%s\n", cmp);
	printf("cmp compare with P = %d \n", my_strcmp(cmp, P));
	my_strcat(P, cmp);
	printf("str P=%s\n", P);
	char* strset = "imsr";
	if (my_strstr(P, strset))
		printf("find string = %s\n", my_strstr(P, strset));

}

int main() {
	test();

	return 0;
}